package com.ossfk.net.config;

import java.net.InetSocketAddress;

import org.apache.commons.lang3.StringUtils;

import lombok.Data;

/**
 * 
 * @ClassName: TcpServerConfig
 * @Description: 服务端配置
 * @author Liujiefu
 * @date 2020-03-13 15:42:52
 */
@Data
public class NetServerConfig {
	/**
	 * 默认端口
	 */
	public static final int DEFULT_PORT = 8000;

	/**
	 * socket地址及端口
	 */
	private InetSocketAddress socketAddress;

	/**
	 * 是否保持连接，默认保持连接
	 */
	private boolean keepAlive = true;
	/**
	 * 读取消息闲置时间默认60秒
	 */
	private Long readerIdleTimeSeconds = 60l;
	/** 服务名称 */
	private String name = "TcpServer";

	/**
	 * 
	 * @Title: TcpServerConfig
	 * @Description: TcpServerConfig构造函数，默认端口8000
	 * @author Liujiefu
	 * @date 2020-03-13 15:47:51
	 */
	public NetServerConfig() {
		this(DEFULT_PORT);
	}
	
	/**
	 * 
	 * @Title: TcpServerConfig
	 * @Description: TcpServerConfig构造函数
	 * @param socketAddress
	 * @author Liujiefu
	 * @date 2020-03-13 15:44:01
	 */
	public NetServerConfig(InetSocketAddress socketAddress) {
		if (socketAddress == null)
			throw new IllegalArgumentException("socketAddress can't be null");
		this.socketAddress = socketAddress;
	}

	/**
	 * 
	 * @Title: TcpServerConfig
	 * @Description: TcpServerConfig构造函数
	 * @param host 主机host或ip地址
	 * @param port 端口
	 * @author Liujiefu
	 * @date 2020-03-13 15:44:29
	 */
	public NetServerConfig(String host, Integer port) {
		if(StringUtils.isNotBlank(host) && port!=null)
			this.socketAddress = new InetSocketAddress(host, port);
		else if(port!=null)
			this.socketAddress = new InetSocketAddress(port);
		else
			this.socketAddress = new InetSocketAddress(DEFULT_PORT);
	}

	/**
	 * 
	 * @Title: TcpServerConfig
	 * @Description: TcpServerConfig构造函数
	 * @param port 端口
	 * @author Liujiefu
	 * @date 2020-03-13 15:44:55
	 */
	public NetServerConfig(int port) {
		this.socketAddress = new InetSocketAddress(port);
	}
}
